
package com.fx.apartment.modules.dynamic.service.impl;

import com.fx.apartment.modules.dynamic.entity.ThumbsUp;
import com.fx.apartment.modules.dynamic.mapper.DynamicMapper;
import com.fx.apartment.modules.dynamic.vo.ThumbsUpVO;
import com.fx.apartment.modules.dynamic.mapper.ThumbsUpMapper;
import com.fx.apartment.modules.dynamic.service.IThumbsUpService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fx.apartment.common.tool.utils.Func;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 朋友圈点赞 服务实现类
 *
 * @author QinXueFeng
 * @since 2021-04-19
 */
@Service
@AllArgsConstructor
public class ThumbsUpServiceImpl extends ServiceImpl<ThumbsUpMapper, ThumbsUp> implements IThumbsUpService {

	private DynamicMapper dynamicMapper;
	@Override
	public IPage<ThumbsUpVO> selectThumbsUpPage(IPage<ThumbsUpVO> page, ThumbsUpVO thumbsUp) {
		return page.setRecords(baseMapper.selectThumbsUpPage(page, thumbsUp));
	}

	@Override
	public boolean deleteByIds(String ids) {
		List<ThumbsUp> thumbsUpList = listByIds(Func.toLongList(ids));
		Map<Long, List<ThumbsUp>> map = thumbsUpList.stream().collect(Collectors.groupingBy(ThumbsUp::getDynamicId));
		map.forEach((k,v)->{
			dynamicMapper.updateCommentNum(k,-v.size());
		});
		return removeByIds(Func.toLongList(ids));
	}

}
